<?php

namespace App;

use Carbon\Carbon;
use FFMpeg\Coordinate\TimeCode;
use Illuminate\Support\Facades\Storage;

class FFMpegUtil
{
    public static function getVideoInfo($streamPath)
    {
        $ffprobe = app('ffprobe');
        $stream  = $ffprobe->streams($streamPath)->videos()->first();
        return $stream ? $stream->all() : [];
    }

    public static function getCover($streamPath, $fromSecond)
    {
        $ffmpeg   = app('ffmpeg');
        $video    = $ffmpeg->open($streamPath);
        $frame    = $video->frame(TimeCode::fromSeconds($fromSecond)); //提取第几秒的图像
        $fileName = str_replace('.mp4', '.jpg', $streamPath);
        $frame->save($fileName);
        return $fileName;
    }
}
